<template>
	<view>
		<view class="my-settle-container">
			<view class="right-box">
				<!-- 全选按钮 -->
				<label @click="changeAllState">
					<radio color="#FF0000" :checked="isFullChecked"/>
					<text>全选</text>
				</label>
				<view class="price-box" v-if="showSettle">
					<text>总计：￥{{checkedGoodsAmount}}</text>
					<text class="save-box">为你节省：￥{{saveMoney}}</text>
				</view>
			</view>
			<!-- 下单、删除 -->
			<view>
				<view  class="btn-settle" @click="operaCart('order')" v-if="showSettle & cart.length !== 0">去下单({{checkedCount}})</view>
				<view class="btn-settle" @click="operaCart('del')" v-if="!showSettle & cart.length !== 0">删除</view>
				<view class="btn-settle" @click="operaCart" v-if="cart.length === 0">去下单(0)</view>
			</view>
		</view>
		<!-- 删除弹出确认框 -->
		<!-- <uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="success" cancelText="我在想想" confirmText="确认删除" content="确认将这N个商品删除吗" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup> -->
	</view>
</template>

<script>
	import {mapGetters,mapActions,mapState} from 'vuex'
	export default {
		name:"my-settle",
		data() {
			return {
				 show: false
			};
		},
		methods:{
			...mapActions('m_cart',['updateAllGoodsState','removeCheckedGoods']),
			/* 全选or	取消全选 */
			changeAllState(){
				// console.log(e.target.checked);
				this.updateAllGoodsState(!this.isFullChecked)
			},
			/* 下单or删除选中的商品 */
			operaCart(value){
				// console.log(e);
				if(value === 'order'){
					console.log('去下单');
				}else if(value === 'del') {
					// this.$refs.alertDialog.open()
				}else{}
			},
			dialogClose() {
				console.log('点击关闭')
			},
			dialogConfirm() {
				console.log('点击确认')
			}
		},
		computed:{
			...mapGetters('m_cart',['checkedCount','total','checkedGoodsAmount','saveAmount']),
			...mapState('m_cart',['cart']),
			/* 全选or取消全选 */
			isFullChecked(){
				return this.checkedCount === this.total
			},
			/* 节省的钱 */
			saveMoney(){
				return (this.saveAmount - this.checkedGoodsAmount).toFixed(2)
			}
		},
		props:{
			showSettle:{
				type:Boolean,
				default:true
			}
		}
	}
</script>

<style lang="scss">
	.my-settle-container {
		height: 100rpx;
		width: 94%;
		font-size: 14px;
		padding: 0 20rpx;
		background-color: white;
		position: fixed;
		bottom: 0;
		left: 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.right-box {
			display: flex;
			justify-content: center;
			align-items: center;
			.price-box {
				color: gray;
				display: flex;
				flex-direction: column;
				margin-left: 40rpx;
				.save-box {
					font-size: 12px;
				}
			}
		}
		.btn-settle {
			background-color: #FF4000;
			color: white;
			height: 40rpx;
			line-height: 40rpx;
			padding: 10rpx 20rpx;
			border-radius: 40rpx;
		}
	}
</style>